package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportTaskExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2020-05-20 17:34:37
 */
@Repository
public class TransportTaskExecutorDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportTaskExecutorDao.class);

    public TransportTaskExecutor insert(final TransportTaskExecutor transportTaskExecutor) {
        insert("TransportTaskExecutor.insert", transportTaskExecutor);
        return transportTaskExecutor;
    }

    public Boolean updateInfoById(final TransportTaskExecutor transportTaskExecutor) {
        return update("TransportTaskExecutor.updateInfoById", transportTaskExecutor) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportTaskExecutor.updateInfoByQuery", query) > 0;
    }

    public TransportTaskExecutor selectById(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return queryForObject("TransportTaskExecutor.selectById", query);
    }

    public List<TransportTaskExecutor> selectByQuery(final Query query) {
        return queryForList("TransportTaskExecutor.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportTaskExecutor.countByQuery", query);
    }

    public Boolean deleteById(final Integer id) {
        TransportTaskExecutor transportTaskExecutor = new TransportTaskExecutor();
        transportTaskExecutor.setDeleteFlag(1);
        transportTaskExecutor.setId(id);

        return update("TransportTaskExecutor.updateInfoById", transportTaskExecutor) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportTaskExecutor.deleteById", query) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByTaskId(final Integer workId, final Integer playerType) {
        Query query = Query.noPage();
        query.put("workId", workId);
        query.put("playerType", playerType);
        return delete("TransportTaskExecutor.deleteByTaskId", query) > 0;
    }
}